package com.bdqn.crm.controller;

import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.bdqn.crm.pojo.Product;
import com.bdqn.crm.service.ProductService;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;

@Controller
public class ProductController {

    @Resource
    private ProductService productService;

    @RequestMapping(value = "product/list")
    public String list(Model model,String prodName,String prodType,String prodBatch,Long pageIndex){
        //数据回显
        model.addAttribute("prodName",prodName);
        model.addAttribute("prodType",prodType);
        model.addAttribute("prodBatch",prodBatch);

        //如果为空,查询第一页
        if (pageIndex == null){
            pageIndex =1L;
        }

        Page<Product> page = new Page<>();
        page.setCurrent(pageIndex);
        IPage<Product> productIPage = productService.page(prodName,prodType,prodBatch,page);
        model.addAttribute("productPage",productIPage);
        return "product/list";
    }
}
